﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Draco.OWF.Acticity;
using Draco.OWF.Transition;
using Draco.OWF.Process;
using Draco.OWF.RT.Engine;
using Draco.OWF.Repository;
using Draco.OWF.Acticity.General;
using Draco.OWF.Repository.Serialize;

namespace Draco.OWF.Demo
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            IActivity ac1 = new EmptyActivity();
            InvokerActivity ac2 = new InvokerActivity();
            IRoute route = new Route(ac1.Id, ac2.Id);

            #region
            ac2.InvokObjectType = "Draco.OWF.Demo.DemoAssembly,Draco.OWF.Demo";
            ac2.InvokObjectRef = "";
            ac2.InvokeMethod = "HelloWord";
            DataBinding.BindingDataItem item = new DataBinding.BindingDataItem();
            item.DataName="name";
            item.DataType = typeof(System.String);
            ac2.InputParameters.Add(item);

            DataBinding.BindingDataItem oitem = new DataBinding.BindingDataItem();
            oitem.DataName = "result";
            oitem.DataType = typeof(System.String);
            ac2.OutputParameters.Add(oitem);
            #endregion

            ProcessDef workflow = new ProcessDef();
            workflow.AddActivity(ac1);
            workflow.AddActivity(ac2);

            workflow.AddRoute(route);

            workflow.EndActivity = ac2;
            workflow.EnsureStartActivity();

            workflow.Check();

            XmlSerializeProvider provider = new XmlSerializeProvider();
            provider.PersistentWorkflowProcess(workflow, new PackageHeader());
            provider.Save("C:\\Users\\Charles\\Desktop\\wf.xml");

            IEngine engine = new DefaultEngine();
            engine.LoadProcess(workflow); 
            engine.CreateJob(workflow,null,null);
        }
    }
}
